import { defineStore } from 'pinia'
import moment from 'moment'

export const useMemberStore = defineStore('member', {
    state: () => ({
        members: [
            {
                "userNumber": "1",
                "birthDate": "2022-02-02",
                "birthPlace": "地球",
                "fullName": "人",
                "awardsList": [
                    {
                        "awardId": 9,
                        "awardName": "一个奖",
                        "description": "大奖",
                        "dateAwarded": "2022-12-01"
                    },
                ]
            }
        ]
    }),
    actions: {
        setMembers (members) {
            this.members = members.map(member => {
                return {
                    ...member,
                    birthDate: moment(member.birthDate).format('YYYY-MM-DD'),
                    awardsList: member.awardsList.map(award => ({
                        ...award,
                        dateAwarded: moment(award.dateAwarded).format('YYYY-MM-DD')
                    }))
                }
            })
        }
    }
})